﻿@using KelonProud
@using KelonProud.Mvc.Models
@model KelonProud.Administration.Dtos.OrganzationInput

@{
    Layout = "~/Views/Shared/_EditMaster.cshtml";
}

@section styles
{
    <style>
        @@media(min-width:300px) {
            .form-horizontal .control-label {
                padding-top: 7px;
                margin-bottom: 0;
                text-align: right;
            }

            .col-sm-3 {
                width: 25%;
                float: left;
            }

            .col-sm-9 {
                width: 75%;
                float: left;
            }
        }
    </style>
}

<div class="box from-box modal-box">
    <form class="form-horizontal" id="EditForm" name="EditForm" validate method="post" role="form">
        @Html.HiddenFor(f => f.Id)
        @Html.HiddenFor(f => f.TenantId)
        <div class="box-body">
            <div class="form-group">
                <label class="col-sm-3 control-label">上级机构</label>
                <div class="col-sm-9">
                    @Html.Partial("~/Views/Shared/Modals/Components/_DropDownTreeView.cshtml", new DropDownTreeModel
                    {
                        Url = "/api/services/admin/organization/GetOrganzationTree?isHasNull=true",
                        IsMilti = false,
                        Name = "ParentId",
                        Value = Model.ParentId
                    })
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">类型</label>
                <div class="col-sm-9">
                    @Html.Partial("Modals/Components/_DropDownSelectView", new DropDownSelectModel()
                       {
                           Name = "OrganizationType",
                           Url = "/api/services/admin/Organization/GetOrganizationTypes",
                           Value = (byte)Model.OrganizationType,
                           IdKey = "id",
                           TextKey = "name",
                           AllowSearch = false,
                           AllowNull = false
                       })
                    <span class="help-block m-b-none">当类型为部门时，该部门上级只能选择[街道/乡镇]</span>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构编号</label>
                <div class="col-sm-9">
                    @Html.TextBoxFor(f => f.Code, new { @class = "form-control validate" })
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <label class="col-sm-3 control-label">机构名称</label>
                <div class="col-sm-9">
                    @Html.TextBoxFor(f => f.DisplayName, new { @class = "form-control validate" })
                </div>
            </div>
             
        </div>
        @Html.Partial("~/Views/Shared/Modals/_ModalFooterWithSaveAndCancel.cshtml")
    </form>
</div>

@section scripts{
    <script>
        function saveFormEvent(_$form) {
            var _navService = abp.services.admin.organization;
            var org = _$form.serializeFormToObject(); //serializeFormToObject is defined in main.js
          
            abp.ui.setBusy(_$form);
            _navService.save(org).done(function() {
                if (org.Id === "0") {
                    abp.notify.success("机构创建成功！");
                } else {
                    abp.notify.success("机构修改成功！");
                }

                DiyWindow.closeModal();

            }).always(function() {
                abp.ui.clearBusy(_$form);
            });
        }
    </script>
}